package com.hk.jmm.db;

import com.skyz.base.manager.LoadingManager;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class DbObserver<T> implements Observer<T> {
    public boolean showLoading = false;

    public DbObserver() {
        this(true) ;
    }

    public DbObserver(boolean showLoading) {
        this.showLoading = showLoading;
    }

    @Override
    public void onSubscribe(@NonNull Disposable d) {
        if (showLoading){
            LoadingManager.getInstance().requestShowDialog();
        }
    }

    @Override
    public void onNext(@NonNull T t) {
        if (showLoading){
            LoadingManager.getInstance().requestDismissDialog();
        }
    }

    @Override
    public void onError(@NonNull Throwable e) {
        if (showLoading){
            LoadingManager.getInstance().requestDismissDialog();
        }
    }

    @Override
    public void onComplete() {

    }
}
